package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanhua.dubbo.mapper.UserMapper;
import com.tanhua.model.domain.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author : xyiaao
 * @createDate : 2022/3/14 15:56
 */
@DubboService
public class UserApiImpl implements UserApi {

    @Autowired
    private UserMapper userMapper;


    /**
     * 根据手机号查询用户
     *
     * @param mobile
     * @return
     */
    @Override
    public User findByMobile(String mobile) {

        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(User::getMobile, mobile);
        return userMapper.selectOne(queryWrapper);
    }

    @Override
    public Long save(User user) {

        userMapper.insert(user);
        return user.getId();
    }

    @Override
    public void update(User user) {

        userMapper.updateById(user);
    }

}
